<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class simpanan extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('auth');
        $this->load->library('base');
        $this->load->library('ajaxresponse');
        $this->load->model("crud/m_simpanan_wajib");
    }

    function index() {
        $this->auth->is_logged_in('form/login');
    }

    function is_new_sw() {
        $this->response = new ajaxresponse();
        $result = $this->m_simpanan_wajib->get("MONTH(BULAN_SIMPANAN) = ".date('m').' AND YEAR(BULAN_SIMPANAN) = '.date('Y'));
        if($result->num_rows() > 0)
            $this->response->status = "FORBID";
        else
            $this->response->status = "ALLOW";
        $this->response->messages = "TEST";
        echo json_encode($this->response);
    }

    function get_sw_new() {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->load->model("crud/m_anggota");
        $this->load->model("crud/m_info_simpanan");
        $data["active_anggota"] = $this->m_anggota->get("STATUS = 1");
        $data["besar_biaya"] = $this->m_info_simpanan->get()->last_row()->SIMPANAN_WAJIB;
        $this->db->trans_start();
        foreach($data["active_anggota"]->result() as $row)
            $this->m_simpanan_wajib->insert($row->ID_ANGGOTA, $data["besar_biaya"]);
        $this->db->trans_complete();
        $this->response->status = "OK";
        echo json_encode($this->response);
    }
}